import Taro, {Component} from '@tarojs/taro'

import {View,Picker,Text} from "@tarojs/components"
import {AtButton, AtIcon, AtList, AtListItem} from "taro-ui"
import './index.scss'
import {getGlobalData} from "../../global.d";
import {getNotice} from "./service";

export default class Index extends Component {
    constructor(props) {
        super(props);
        this.state = {
            current: 0,
            selector:[['全部','学校通知','活动通知','比赛通知','考试通知'],['全部','进行中','已截止']],
            selectorChecked:'全部&全部',
          json: []
        }
    }
  componentWillMount(){

  }
  componentDidMount(){
    setTimeout(()=>{
      const user =  getGlobalData('user')
      this.getjson(user.userLastTimeClass.classKey)
    },2000)

  }
  async getjson(classKey){
      await getNotice(classKey).then(res=>{
        this.setState({
          json: res.data
        })
      })
  }
  onChange = e => {

      this.setState({
      selectorChecked: this.state.selector[0][e.detail.value[0]]+'&'+this.state.selector[1][e.detail.value[1]]
      })
  }
    render() {

        return (
            <View>
              <View className='selectorChecked'>
                <Picker mode='multiSelector'
                        range={this.state.selector}
                        onChange={this.onChange}
                >
                  <View className='pickerItem'>
                    <AtIcon prefixClass='icon' value='guolv' size='25' color='#719BEA'></AtIcon>
                    <Text> {this.state.selectorChecked}</Text>
                    <View className='icon_2'>
                      <AtIcon   value='chevron-down' size='25' color='#CCCCCC'></AtIcon>
                    </View>

                  </View>
                </Picker>
              </View>
              <View>
                <AtList>
                  {
                    this.state.json.map((item,index)=>{
                      return (
                        <AtListItem
                          title={item.title}
                          note={item.content}
                          extraText='详细信息'
                          arrow='right'
                          iconInfo={{ size: 25, color: '#FF4949', value: 'check', }}
                        />
                      )
                    })
                  }
                </AtList>
              </View>

            </View>
        )
    }

}
